package com.campus.controller;

import com.campus.common.Result;
import com.campus.domain.Dto.ClassCreateDto;
import com.campus.domain.Dto.ClassUpdateDto;
import com.campus.service.IClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/class")
@Slf4j
public class ClassController {

    @Autowired
    private IClassService classService;

    @PostMapping("/add")
    private Result addClass(@RequestBody @Validated ClassCreateDto classCreateDto) {
        int rs = classService.addClass(classCreateDto);
        return rs == 1 ? Result.success() : Result.error();
    }

    @PutMapping("/update")
    private Result updateClass(@RequestBody @Validated ClassUpdateDto classUpdateDto) {
        int rs = classService.updateClass(classUpdateDto);
        return rs == 1 ? Result.success() : Result.error();
    }

    @PutMapping("/allocateTeacher/{classId}")
    private Result allocateTeacher(@Validated @NotNull Long teacherId,@PathVariable @Validated @NotNull Long classId) {
        int rs = classService.allocateTeacher(teacherId,classId);
        return rs == 1 ? Result.success() : Result.error();
    }

    @PutMapping("/add/student/{classId}")
    private Result addStudentInClass(@Validated @NotNull Long studentId,@PathVariable @Validated @NotNull Long classId) {
        int rs = classService.addStudentInClass(classId,studentId);
        return rs == 1 ? Result.success() : Result.error();
    }

}
